/**
 * 
 */
package com.workManager.base;

import com.workManager.config.RespCode;
import org.springframework.ui.ModelMap;

/**
 * 
* @ClassName: BaseException 
* @Description: 自定义基础类型，系统所有异常必须继承改类
* @author xucan
* @date 2016年11月4日 上午11:55:03 
*
 */
@SuppressWarnings("serial")
public abstract class BaseException extends RuntimeException {
	
	protected RespCode respCode;
	
	public BaseException() {
	}

	public BaseException(Throwable ex) {
		super(ex);
	}

	public BaseException(String message) {
		super(message);
	}

	public BaseException(String message, Throwable ex) {
		super(message, ex);
	}
	
	public BaseException(RespCode respCode, Throwable ex) {
		super(respCode.msg(), ex);
		this.respCode = respCode;
	}
	
	public BaseException(RespCode respCode) {
		super(respCode.msg());
		this.respCode = respCode;
	}

	public void handler(ModelMap modelMap) {
		RespCode respCode = (this.respCode==null)?getRespCode():this.respCode;
		modelMap.put("code", respCode.value());
		modelMap.put("msg", respCode.msg());
		modelMap.put("timestamp", System.currentTimeMillis());
	}

	protected abstract RespCode getRespCode();
}
